{extend name="admin@index_layout"/}
{block name="main"}
<style type="text/css">
.btn-repeat{position: absolute;right: 7px;top: 7px;}
</style>
<form class="layui-form form-horizontal" method="post">
    {include file="admin@inputItem" /}
    <input type="hidden" name="modelField[catid]" value="{$catid}">
    {if count($fieldList)}
    <div class="layui-form-item">
        <div>
            <button class="layui-btn ajax-post1" target-form="form-horizontal">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    {/if}
</form>
{/block}
{block name="script"}
<script type="text/javascript">
layui.use(['form','layer'], function() {
    var form = layui.form;
    {notempty name='cmsConfig.web_site_getwords'}
    GV.ueditor_getwords_url="{:url('addons/getwords/getkeywords',['isadmin'=>1])}";
    $(".content_attr").append('<a class="layui-btn layui-btn-sm" id="getwords" style="margin-top: 4px;">提取关键词</a> ');
    {/notempty}
    $(".content_attr").append("<input type='checkbox' name='modelField[get_introduce]' title='是否截取到内容摘要' checked> <input type='checkbox' name='modelField[auto_thumb]' title='是否提取到缩略图' checked>");
    form.render();

    var input =$("input[name='modelField[title]']");
    input.after("<button type='button' class='layui-btn layui-btn-sm btn-repeat'>重复检测</button>");
    $('.btn-repeat').on('click', function(e) {
        $.get("{:url('check_title')}", {'catid':{$catid},'data':input.val()}, function(res) {
            if(res.code==1){
                layer.msg(res.msg,{icon: 1});
            }else{
                layer.msg(res.msg,{icon: 0});
            }
        })
    });

    $('.ajax-post1').on('click', function(e) {
        var form = layui.form,
        layer = layui.layer,target,
        target_form = $(this).attr('target-form');
        target = $('.form-horizontal').attr("action");
        $.post(target, $('.form-horizontal').serialize()).success(function(data) {
            if (data.code == 1) {
                layer.confirm(data.msg, {
                    btn: ['继续添加', '返回列表'] //按钮
                }, function() {
                    location.href = '{:url("add",["catid"=>$catid])}';
                }, function() {
                    parent.layui.table.reload('currentTable');
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                });
            } else {
                layer.msg(data.msg);
            }
        });
        return false;
    });
})
</script>
{/block}
